package com.android.jay.wzp_voice.view.login;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import android.util.Log;
import android.view.View;

import com.android.jay.lib_commin_ui.base.BaseActivity;
import com.android.jay.lib_network.okhttp.response.listener.DisposeDataListener;
import com.android.jay.wzp_voice.R;
import com.android.jay.wzp_voice.api.RequestCenter;
import com.android.jay.wzp_voice.model.user.LoginEvent;
import com.android.jay.wzp_voice.model.user.User;
import com.android.jay.wzp_voice.view.login.manager.UserManager;

import org.greenrobot.eventbus.EventBus;

import androidx.annotation.Nullable;

/**
 * Created by wzp on 2020/1/6 0006.
 * <p>
 * 描述  ：登录页面
 */
public class LoginActivity extends BaseActivity {
      public static void start(Context context){

          Intent intent = new Intent(context,LoginActivity.class);
          context.startActivity(intent);
      }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_layout);
        findViewById(R.id.login_view).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RequestCenter.login(new DisposeDataListener() {
                    @Override
                    public void onSuccess(Object responseObj) {
                        //处理拿到登录信息 正常逻辑
                        User user = (User) responseObj;
                        UserManager.getInstance().saveUser(user);
                        EventBus.getDefault().post(new LoginEvent());
                        finish();
                    }

                    @Override
                    public void onFailure(Object reasonObj) {
                        //登录失败逻辑
                        Log.e("wzp","ex=="+reasonObj.toString());

                    }
                });
            }
        });

    }
}
